﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Xml.Serialization;

namespace PSE.Framework.Communication.Spb.Common.Error
{
    public abstract class BaseMessageError
    {
        [XmlAttribute("CodErro")]
        public string CodigoErro { get; set; }

        public List<string> ListErrors()
        {
            List<string> retorno = new List<string>();
            PropertyInfo[] properties = this.GetType().GetProperties();
            Type typeElementError = typeof(Error.ElementError);
            Error.ElementError valor;

            if (!string.IsNullOrEmpty(this.CodigoErro))
                retorno.Add(this.CodigoErro);

            foreach (PropertyInfo property in properties)
            {
                if (property.PropertyType == typeElementError)
                {
                    valor = (Error.ElementError)property.GetValue(this, null);

                    if (valor != null)
                    {
                        if (!retorno.Contains(valor.CodigoErro) && !string.IsNullOrEmpty(valor.CodigoErro))
                            retorno.Add(valor.CodigoErro);
                    }
                }
            }

            return retorno;
        }
    }
}
